﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using LabMS.BLL;
using LabMS.Model;

namespace LabMS.Web.LabPersonnel
{
    public partial class EditPositionLog : Base.BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            strPagePrivilege.Add("GWRZGL");
            strPageUserType.Add("mana");
            strPageUserType.Add("teacher");
            PLogTime.Attributes.Add("onclick", "d.showMoreDay = false;d.show(this);");
            PLogTime.Attributes.Add("readOnly", "-1");
            PLogTeacherName.Attributes.Add("readOnly","-1");
            if (Request.QueryString["id"] == null)
            {
                Common.JShelper.JSAlert(Page, "err", "参数错误!");
                return;
            }
            int ID = 0;
            if (!int.TryParse(Request.QueryString["ID"], out ID))
            {
                Common.JShelper.JSAlert(Page, "err", "参数错误!");
                return;
            }
            if (!IsPostBack)
            {
                BindData(ID);
            }
        }

        //绑定数据
        private void BindData(int ID)
        {
            LabMS.BLL.PositionLog pLog = new LabMS.BLL.PositionLog();
            LabMS.Model.PositionLog pLogInfo = new LabMS.Model.PositionLog();

            pLogInfo = pLog.GetModel(ID);
            PLogTeacherName.Text = pLogInfo.PLog_TeacherName;
            PLogTime.Text = pLogInfo.PLog_Time.Value.ToShortDateString();
            PLogEquipment.Text = pLogInfo.PLog_Equipment;
            PLogLabIntro.Text = pLogInfo.PLog_LabIntro;
            PLogOther.Text = pLogInfo.PLog_Other; 
        }

        protected void Submit_OnClick(object sender, EventArgs e)
        {
            #region 验证
            if (string.IsNullOrEmpty(PLogTeacherName.Text.Trim()))
            {
                LabMS.Common.JShelper.JSAlert(Page, "err", "教师名称不能为空!");
                return;
            }
            else if (PLogTeacherName.Text.Trim().Length > 40)
            {
                LabMS.Common.JShelper.JSAlert(Page, "err", "教师名称不能超过40字符!");
                return;
            }
            if (string.IsNullOrEmpty(PLogTime.Text.Trim()))
            {
                LabMS.Common.JShelper.JSAlert(Page, "err", "时间不能为空!");
                return;
            }
            if (string.IsNullOrEmpty(PLogLabIntro.Text.Trim()))
            {
                LabMS.Common.JShelper.JSAlert(Page, "err", "实验教学情况不能为空!");
                return;
            }
            else if (PLogLabIntro.Text.Trim().Length > 100)
            {
                LabMS.Common.JShelper.JSAlert(Page, "err", "实验教学简况长度不能超过100个字符!");
                return;
            }
            if (string.IsNullOrEmpty(PLogEquipment.Text.Trim()))
            {
                LabMS.Common.JShelper.JSAlert(Page, "err", "仪器设备运行情况不能为空!");
                return;
            }
            else if (PLogEquipment.Text.Trim().Length > 100)
            {
                LabMS.Common.JShelper.JSAlert(Page, "err", "仪器设备运行情况长度不能超过100个字符!");
                return;
            }
            if (PLogOther.Text.Trim().Length > 100)
            {
                LabMS.Common.JShelper.JSAlert(Page, "err", "其它情况长度不能超过100个字符!");
                return;
            }
            #endregion

            LabMS.Model.PositionLog posLog = new LabMS.Model.PositionLog();
            LabMS.Model.PositionLog posLogTemp = new LabMS.Model.PositionLog();
            LabMS.BLL.PositionLog posLogInfo = new LabMS.BLL.PositionLog();

            //posLog.ID = int.Parse(Request.QueryString["ID"]);
            //posLog.PLog_TeacherCode = positionLog.GetTeacherCode(PLogTeacherName.Text.Trim());
            //posLog.PLog_TeacherName = PLogTeacherName.Text.Trim();
            int PID = 0;
            if (!int.TryParse(Request.QueryString["ID"], out PID))
            {
                Common.JShelper.JSAlert(Page, "err", "参数错误!");
                return;
            }
            posLogTemp = posLogInfo.GetModel(PID);
            posLog.ID = posLogTemp.ID;
            posLog.PLog_TeacherCode = posLogTemp.PLog_TeacherCode;
            posLog.PLog_TeacherName = posLogTemp.PLog_TeacherName;
            posLog.PLog_IP = posLogTemp.PLog_IP;
            posLog.PLog_Time = Convert.ToDateTime(PLogTime.Text.Trim());
            posLog.PLog_LabIntro = PLogLabIntro.Text.ToString().Trim();
            posLog.PLog_Equipment = PLogEquipment.Text.Trim();
            posLog.PLog_Other = PLogOther.Text.Trim();
            posLog.PLog_RecodeTime = DateTime.Now;

            posLogInfo.Update(posLog);
            LabMS.Common.JShelper.JSAlertAndRedirect(Page, "EditSuccess", "修改成功!", "ListPositionLog.aspx");  
        }
    }
}
